﻿using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;
#if UNITY_EDITOR 
using UnityEditor;
#endif

namespace MyAssetBundles {
    public class MyAssetBundlesConfig {
        // 在线更新资源服务器地址
        public static string AssetBundlesServerUrl
        {
            get { return "http://ixnan.com/unityAssetBundles/civ/"; }
        }

        public static string VersionsFileName
        {
            get { return "civ.version"; }
        }

        // 更新包后缀名
        public static string PackageExtension
        {
            get { return ".civ"; }
        }

        public static string AssetBundleExtension
        {
            get {
                return ".ab";
            }
        }

        public static string ManifestExtension
        { 
            get {
                return ".manifest";
            }
        }

        // 更新文件存放路径
        public static string AssetBundlesPath
        {
            get {
#if UNITY_EDITOR
                return MyAssetBundlesUtil.PathCombine(PackageSavePath, PlatformName);
#else
                return MyAssetBundlesUtil.PathCombine(PackageSavePath, "AssetBundles"); 
#endif
            }
        }

        // 更新包本地保存路径
        public static string PackageSavePath
        {
            get {
#if UNITY_EDITOR
                return "OnlineResources";
#else
                return Application.persistentDataPath;
#endif
            }
        }
        
        // 获取APP启动时更新文件后缀
        public static List<string> GetExtensionWithUpdateMode (MyAssetBundlesUpdateMode updateMode)
        {
            List<string> extensionList = new List<string>();
            switch (updateMode)
            {
                case MyAssetBundlesUpdateMode.Force:
                    extensionList.Add("");
                    extensionList.Add(AssetBundleExtension);
                    break;
                case MyAssetBundlesUpdateMode.Silence:
                    extensionList.Add("");
                    extensionList.Add(".bs");
                    break;
            }
            return extensionList;
        }

        // 平台string
        public static string PlatformName
        {
            get {
#if UNITY_EDITOR
                switch (EditorUserBuildSettings.activeBuildTarget)
                {
                    case BuildTarget.Android:
                        return "Android";
                    case BuildTarget.iOS:
                        return "iOS";
                    case BuildTarget.StandaloneWindows:
                    case BuildTarget.StandaloneWindows64:
                        return "Windows";
                    default:
                        return "Unknown";
                }
#else
                switch (Application.platform)
                {
                    case RuntimePlatform.Android:
                        return "Android";
                    case RuntimePlatform.IPhonePlayer:
                        return "iOS";
                    case RuntimePlatform.WindowsPlayer:
                        return "Windows";
                    default:
                        return "Unknown";
                }
#endif
            }
        }
    }
}

